package com.situ.crm.rbac.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.situ.crm.bean.pojo.User;
import com.situ.crm.bean.vo.UserExcelVO;
import com.situ.crm.rbac.mapper.UserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

//这个类没有被Spring管理
public class UserExcelListener extends AnalysisEventListener<UserExcelVO>{
    //@Autowired
    private UserMapper userMapper;

    public UserExcelListener(UserMapper userMapper){
        this.userMapper = userMapper;
    }

    @Override
    public void invoke(UserExcelVO userExcelVO, AnalysisContext analysisContext) {
        System.out.println("UserExcelListener.invoke");
        User user = new User();
        BeanUtils.copyProperties(userExcelVO, user);
        userMapper.insert(user);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("UserExcelListener.doAfterAllAnalysed");
    }
}
